In [ ]:
from test_functions import *
import json

with open("test_streams.json", "r") as file:
    test_streams = json.load(file)
In [ ]:
# start a local instance of the API, then run the tests
# NOTE: there is an hourly limit to the number of calls we can make to the USGS water data API
# If you see errors fetching observed data, this is likely the reason why

# note that the y scale is plotted using symlog so that both small and large flows can be seen on the same plot.
# flows between 0 and 1 are plotted linearly, flows above 1 are plotted logarithmically.
# even so, some horizontal line artifacts may appear at 10^0 (i.e, flow values of 1) in observed data where
# flow values are rounded to whole numbers.
In [ ]:
run_test_suite(test_streams)
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
Problem getting observed data for stream ID: 29015. Skipping.
Problem getting observed data for stream ID: 17871. Skipping.
Problem getting observed data for stream ID: 24828. Skipping.
Problem getting observed data for stream ID: 4521. Skipping.
Problem getting observed data for stream ID: 4889. Skipping.
Problem getting observed data for stream ID: 4847. Skipping.
Problem getting observed data for stream ID: 9245. Skipping.
Problem getting observed data for stream ID: 34617. Skipping.
Problem getting observed data for stream ID: 35668. Skipping.
Problem getting observed data for stream ID: 9176. Skipping.
Problem getting observed data for stream ID: 6260. Skipping.
Problem getting observed data for stream ID: 8705. Skipping.
Problem getting observed data for stream ID: 4464. Skipping.
Problem getting observed data for stream ID: 19784. Skipping.
Problem getting observed data for stream ID: 20915. Skipping.
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[3], line 1
----> 1 run_test_suite(test_streams)

File ~/hydroviz/data/tests/test_functions.py:37, in run_test_suite(test_streams)
     34 stats_list = []
     36 for stream_dict in reformat_test_stream_dict(test_streams):
---> 37     modeled_data = fetch_modeled_climatology_data(stream_dict["hydroviz_stream_id"])
     39     if modeled_data is None:
     40         print(
     41             f"Problem getting modeled data for stream ID: {stream_dict['hydroviz_stream_id']}. Skipping."
     42         )

File ~/hydroviz/data/tests/test_functions.py:114, in fetch_modeled_climatology_data(hydroviz_stream_id)
    108 modeled_data = {
    109     "dynamic": {"doy": [], "min_values": [], "mean_values": [], "max_values": []},
    110     "static": {"doy": [], "min_values": [], "mean_values": [], "max_values": []},
    111 }
    113 url = api_base_url + f"conus_hydrology/modeled_climatology/{hydroviz_stream_id}"
--> 114 response = requests.get(url)
    115 if response.status_code == 200:
    116     data = response.json()

File ~/miniconda3/envs/snap-geo/lib/python3.11/site-packages/requests/api.py:73, in get(url, params, **kwargs)
     62 def get(url, params=None, **kwargs):
     63     r"""Sends a GET request.
     64 
     65     :param url: URL for the new :class:`Request` object.
   (...)     70     :rtype: requests.Response
     71     """
---> 73     return request("get", url, params=params, **kwargs)

File ~/miniconda3/envs/snap-geo/lib/python3.11/site-packages/requests/api.py:59, in request(method, url, **kwargs)
     55 # By using the 'with' statement we are sure the session is closed, thus we
     56 # avoid leaving sockets open which can trigger a ResourceWarning in some
     57 # cases, and look like a memory leak in others.
     58 with sessions.Session() as session:
---> 59     return session.request(method=method, url=url, **kwargs)

File ~/miniconda3/envs/snap-geo/lib/python3.11/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    584 send_kwargs = {
    585     "timeout": timeout,
    586     "allow_redirects": allow_redirects,
    587 }
    588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
    591 return resp

File ~/miniconda3/envs/snap-geo/lib/python3.11/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs)
    700 start = preferred_clock()
    702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
    705 # Total elapsed time of the request (approximately)
    706 elapsed = preferred_clock() - start

File ~/miniconda3/envs/snap-geo/lib/python3.11/site-packages/requests/adapters.py:644, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    641     timeout = TimeoutSauce(connect=timeout, read=timeout)
    643 try:
--> 644     resp = conn.urlopen(
    645         method=request.method,
    646         url=url,
    647         body=request.body,
    648         headers=request.headers,
    649         redirect=False,
    650         assert_same_host=False,
    651         preload_content=False,
    652         decode_content=False,
    653         retries=self.max_retries,
    654         timeout=timeout,
    655         chunked=chunked,
    656     )
    658 except (ProtocolError, OSError) as err:
    659     raise ConnectionError(err, request=request)

File ~/miniconda3/envs/snap-geo/lib/python3.11/site-packages/urllib3/connectionpool.py:787, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    784 response_conn = conn if not release_conn else None
    786 # Make the request on the HTTPConnection object
--> 787 response = self._make_request(
    788     conn,
    789     method,
    790     url,
    791     timeout=timeout_obj,
    792     body=body,
    793     headers=headers,
    794     chunked=chunked,
    795     retries=retries,
    796     response_conn=response_conn,
    797     preload_content=preload_content,
    798     decode_content=decode_content,
    799     **response_kw,
    800 )
    802 # Everything went great!
    803 clean_exit = True

File ~/miniconda3/envs/snap-geo/lib/python3.11/site-packages/urllib3/connectionpool.py:534, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    532 # Receive the response from the server
    533 try:
--> 534     response = conn.getresponse()
    535 except (BaseSSLError, OSError) as e:
    536     self._raise_timeout(err=e, url=url, timeout_value=read_timeout)

File ~/miniconda3/envs/snap-geo/lib/python3.11/site-packages/urllib3/connection.py:571, in HTTPConnection.getresponse(self)
    568 _shutdown = getattr(self.sock, "shutdown", None)
    570 # Get the response from http.client.HTTPConnection
--> 571 httplib_response = super().getresponse()
    573 try:
    574     assert_header_parsing(httplib_response.msg)

File ~/miniconda3/envs/snap-geo/lib/python3.11/http/client.py:1395, in HTTPConnection.getresponse(self)
   1393 try:
   1394     try:
-> 1395         response.begin()
   1396     except ConnectionError:
   1397         self.close()

File ~/miniconda3/envs/snap-geo/lib/python3.11/http/client.py:325, in HTTPResponse.begin(self)
    323 # read until we get a non-100 response
    324 while True:
--> 325     version, status, reason = self._read_status()
    326     if status != CONTINUE:
    327         break

File ~/miniconda3/envs/snap-geo/lib/python3.11/http/client.py:286, in HTTPResponse._read_status(self)
    285 def _read_status(self):
--> 286     line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    287     if len(line) > _MAXLINE:
    288         raise LineTooLong("status line")

File ~/miniconda3/envs/snap-geo/lib/python3.11/socket.py:718, in SocketIO.readinto(self, b)
    716 while True:
    717     try:
--> 718         return self._sock.recv_into(b)
    719     except timeout:
    720         self._timeout_occurred = True

KeyboardInterrupt: 
In [ ]: